package com.dalongxin.work.data;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class Company extends SelectionBase {

    public static Company parseFromJson(JSONObject jsonObject) {
        Company selectionBase = new Company();
        selectionBase.setId(jsonObject.optInt("id"));
        selectionBase.setName(jsonObject.optString("name"));
        return selectionBase;
    }

    public static List<Company> parseFromJsonList(JSONArray jsonArray) {
        List<Company> list = new ArrayList<>();
        if(jsonArray != null && jsonArray.length() > 0) {
            for(int i=0;i<jsonArray.length();i++) {
                Company item = parseFromJson(jsonArray.optJSONObject(i));
                if(item != null)list.add(item);
            }
        }
        return list;
    }
}
